<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
</head>
<body>
    <input id="text" type="text">
    <script>
        const text = document.querySelector('#text')
        text.onfocus = () => {
            
            text.value = '请输入搜索关键字'
            text.style.color = 'black'
            // console.log('focus')
        }
        text.onblur = () => {
            if (text.value == '') {
                text.value = '请输入搜索关键字'
                text.style.color = 'grey'
            }
            // console.log('blur')
        }
    </script>
</body>
</html>